package com.isnmp.nms.framework.discover.service;

import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import com.isnmp.common.snmp.SNMPTarget;
import com.isnmp.common.snmp.mib.MibMacIP;
import com.isnmp.nms.framework.discover.DeviceInfo;
import com.isnmp.nms.framework.discover.DeviceTypeInfo;
import com.isnmp.nms.framework.discover.DiscoverConfig;

public class SearchDeviceByIPRoaming {
    private List<DeviceInfo> allRoamedDeviceList = new Vector();

    private boolean isDeviceExist(String paramString1, String paramString2) {
        DeviceInfo localDeviceInfo1 = new DeviceInfo();
        localDeviceInfo1.setDeviceIP(paramString1);
        localDeviceInfo1.setDeviceMAC(paramString2);
        Iterator localIterator = this.allRoamedDeviceList.iterator();
        while (localIterator.hasNext()) {
            DeviceInfo localDeviceInfo2 = (DeviceInfo) localIterator.next();
            if (localDeviceInfo2.equals(localDeviceInfo1))
                return true;
        }
        return false;
    }

    public List<DeviceInfo> searchDeviceByIPRoaming(List<String> paramList, List<SNMPTarget> paramList1, boolean paramBoolean, int paramInt1, int paramInt2) {
        if (paramInt1 >= 8)
            paramInt1 = 8;
        if (paramInt2 >= 1024)
            paramInt2 = 1024;
        List localList = new SearchNodeService().searchDeviceByNetList(paramList, paramList1, paramBoolean);
        this.allRoamedDeviceList.addAll(localList);
        for (int i = 1; i <= paramInt1; i++) {
            if (this.allRoamedDeviceList.size() >= paramInt2)
                break;
            localList = getOtherDeviceByRouter(localList, paramList1, paramBoolean);
            this.allRoamedDeviceList.addAll(localList);
        }
        return this.allRoamedDeviceList;
    }

    public List<DeviceInfo> searchDeviceByIPRoaming(String paramString, List<SNMPTarget> paramList, boolean paramBoolean, int paramInt1, int paramInt2) {
        if (paramInt1 >= 8)
            paramInt1 = 8;
        if (paramInt2 >= 1024)
            paramInt2 = 1024;
        Vector localVector = new Vector();
        localVector.add(paramString);
        List localList = new SearchNodeService().searchDeviceByIPList(localVector, paramList, paramBoolean);
        this.allRoamedDeviceList.addAll(localList);
        for (int i = 1; i <= paramInt1; i++) {
            localList = getOtherDeviceByRouter(localList, paramList, paramBoolean);
            this.allRoamedDeviceList.addAll(localList);
            if (this.allRoamedDeviceList.size() >= paramInt2)
                break;
        }
        return this.allRoamedDeviceList;
    }

    private List<DeviceInfo> getOtherDeviceByRouter(List<DeviceInfo> paramList, List<SNMPTarget> paramList1, boolean paramBoolean) {
        Vector localVector1 = new Vector();
        Vector localVector2 = new Vector();
        Object localObject2 = paramList.iterator();
        while (((Iterator) localObject2).hasNext()) {
            Object localObject1 = (DeviceInfo) ((Iterator) localObject2).next();
            if ((DiscoverConfig.isIPRoamingAll) || (((DeviceInfo) localObject1).getDeviceType().equalsLogicType(DeviceTypeInfo.RouterType)) || (((DeviceInfo) localObject1).getDeviceType().equalsLogicType(DeviceTypeInfo.RouterSwitchType))) {
                Object localObject3 = ((DeviceInfo) localObject1).getMibMacIPList();
                Iterator localIterator = ((List) localObject3).iterator();
                while (localIterator.hasNext()) {
                    MibMacIP localMibMacIP = (MibMacIP) localIterator.next();
                    if (localMibMacIP.getIpNetToMediaType() != 2) {
                        String str1 = localMibMacIP.getIpNetToMediaNetAddress();
                        String str2 = localMibMacIP.getIpNetToMediaPhysAddress();
                        if ((!isDeviceExist(str1, str2)) && (!localVector2.contains(str1)))
                            localVector2.add(str1);
                    }
                }
            }
        }
        Object localObject1 = new SearchNodeService().searchDeviceByIPList(localVector2, paramList1, paramBoolean);
        Object localObject3 = ((List) localObject1).iterator();
        while (((Iterator) localObject3).hasNext()) {
            localObject2 = (DeviceInfo) ((Iterator) localObject3).next();
            if (!this.allRoamedDeviceList.contains(localObject2))
                localVector1.add(localObject2);
        }
        return localVector1;
    }
}